﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;

namespace FPC.Offer.UI.GeneralProcessor.SkyDriveHand
{
    /// <summary>
    /// IndexAddHandler 的摘要说明
    /// </summary>
    public class IndexAddHandler : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/html";
            var FName = context.Request["name"];
            FPC.Offer.Service.System_FolderTableService Skyt = new Service.System_FolderTableService();

            string pat = System.AppDomain.CurrentDomain.BaseDirectory + FName;
            //string path = Server.mapPath("") + "\\" + name;
            if (Directory.Exists(pat))
            {
                context.Response.Write("<script>location.href='../SkyDrive/wangpanindex.aspx/'</script>");
                return;
            }
            else
            {


                DirectoryInfo folder = Directory.CreateDirectory(pat);
                string time = Convert.ToString(Directory.GetCreationTime(pat));
                string foldername = FName.Substring(FName.LastIndexOf("\\") + 1);
                Model.Folder s = new Model.Folder();
                s.FName = FName;
                s.Furl = pat;

                int a = Skyt.Add(s);
                if (a > 0)
                {
                    context.Response.Redirect("/SkyDrive/wangpanindex.aspx");
                    return;
                }
                else
                {

                    context.Response.Write("<script>alert('添加失败');</script>");
                    return;
                }

            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}